package hn.sigit.logic.workflow.transaction.impl;

import hn.sigit.logic.workflow.transaction.ApprovalHelper;
import hn.sigit.logic.workflow.transaction.TransactionHelper;
import hn.sigit.model.hnd.ladmshadow.Parcel;
import hn.sigit.dao.hnd.ladmshadow.ParcelDAO;
import java.util.List;

import javax.ejb.Remove;
import javax.ejb.Stateful;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

@Name("approvalHelper")
@Scope(value=ScopeType.CONVERSATION)
@AutoCreate
public class ApprovalHelperImpl implements ApprovalHelper {
	private static final long serialVersionUID = 1L;
	
	private TransactionHelper transactionHelper;
	private long presentationId;
	
	private List<Parcel> beforeParcelList;
	private List<Parcel> afterParcelList;
	
	
	public ApprovalHelperImpl() {
		transactionHelper = (TransactionHelper)Component.getInstance("transactionHelper");
		presentationId = transactionHelper.getTransactionId();
	}
	
	@Override
	public List<Parcel> getBeforeParcelList() {
		if (beforeParcelList == null) {
			beforeParcelList = ParcelDAO.loadBeforeParcelsByPresentationId(presentationId);
		}
		return beforeParcelList;
	}
	@Override
	public void setBeforeParcelList(List<Parcel> beforeParcelList) {
		this.beforeParcelList = beforeParcelList;
	}
	
	@Override
	public List<Parcel> getAfterParcelList() {
		if (afterParcelList == null) {
			afterParcelList = ParcelDAO.loadRequestedParcelsByPresentationId(presentationId);
		}
		return afterParcelList;
	}
	@Override
	public void setAfterParcelList(List<Parcel> afterParcelList) {
		this.afterParcelList = afterParcelList;
	}
	
	@Override
	public List<Parcel> getParcelList(String listIdx) {
		if (listIdx.equals("0"))
			return getBeforeParcelList();
		
		return getAfterParcelList();
	}
	
	@Destroy
	@Remove
	public void destroy() {
	}
}
